package Prefix_and;

import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-01-23
 * Time:16:00
 * Text：二维前缀和
 */
public class Text2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int col = sc.nextInt();
        int[][] array1 = new int[row + 1][col + 1];
        int num = sc.nextInt();
        for (int i = 1; i < row + 1; i++) {
            for (int k = 1; k < col + 1; k++) {
                array1[i][k] = sc.nextInt();
            }
        }
        long[][] dp = new long[row + 1][col + 1];
        for (int i = 1; i < row + 1; i++) {
            for (int k = 1; k < col + 1; k++) {
                dp[i][k] = dp[i - 1][k] + dp[i][k - 1] + array1[i][k] - dp[i - 1][k - 1];
            }
        }
        while (num-- > 0) {
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int x2 = sc.nextInt();
            int y2 = sc.nextInt();
            long S = dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1];
            System.out.println(S);

        }
    }


}
